﻿using MsBox.Avalonia.Enums;
using MsBox.Avalonia;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia;
using System.Drawing;
using Icon = MsBox.Avalonia.Enums.Icon;

namespace 畜牧业审核程序国产.Models
{
    internal class MyMessagebox
    {
        public static async Task Show(string message)
        {
            string MyMessage = message as string;
            var MessageBox = MessageBoxManager.GetMessageBoxStandard("提示", MyMessage, ButtonEnum.Ok);
            if (MessageBox != null)
            {
                //Window window = CurrentPage as Window;
                //var Result = await MessageBox.ShowAsPopupAsync(owner:window);
                await MessageBox.ShowAsync();
            }
        }
        public static async Task Show(string message,Icon icon=Icon.Success)
        {
            string MyMessage = message as string;
            var MessageBox = MessageBoxManager.GetMessageBoxStandard("提示", MyMessage, ButtonEnum.Ok,icon);
            if (MessageBox != null)
            {
                //Window window = CurrentPage as Window;
                //var Result = await MessageBox.ShowAsPopupAsync(owner:window);
                await MessageBox.ShowAsync();
            }
        }
        public static async Task<ButtonResult> Show(string message, ButtonEnum btnEnum, Icon icon)
        {
            string MyMessage = message as string;
            var MessageBox = MessageBoxManager.GetMessageBoxStandard("提示", MyMessage,  btnEnum,icon);
            if (MessageBox != null)
            {
                //Window window = CurrentPage as Window;
                var Result =await   MessageBox.ShowAsync();
                return Result;
            }

            return ButtonResult.No;
        }
        public static async Task<ButtonResult> ShowAsync(string messageWords, Avalonia.Controls.Window CurrentPage,MsBox.Avalonia.Enums.Icon icon)
        {
            string MessageWords = messageWords as string;
            var MessageBox = MessageBoxManager.GetMessageBoxStandard("提示", MessageWords,ButtonEnum.OkCancel,icon);
            if (MessageBox != null)
            {
                Window window = CurrentPage as Window;
                if (window != null)
                {
                    var Result = await MessageBox.ShowWindowDialogAsync(CurrentPage);
                    return Result;
                }

            }
            return ButtonResult.None;
        }
        public static async Task<ButtonResult> ShowAsync(string messageWords,Avalonia.Controls.Window parentWindow,MsBox.Avalonia.Enums.Icon icon,MsBox.Avalonia.Enums.ButtonEnum buttonEnum)
        {
            string MessageWords = messageWords as string;
            var MessageBox = MessageBoxManager.GetMessageBoxStandard("提示", MessageWords, buttonEnum, icon);
            if (MessageBox != null)
            {
               
                if (parentWindow  != null)
                {
                    var Result = await MessageBox.ShowWindowDialogAsync(parentWindow);
                    return Result;
                }

            }
            return ButtonResult.None;
        }
        public static Window GetMainWindow()
        {
            if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)//可以使用全局的 Application 对象来获取当前应用程序的主窗口及其生命周期信息
            {
                return desktop.MainWindow;
            }
            return null;
        }
        public static async Task<ButtonResult> ShowAsyncInMainWindow(string message,Icon icon)
        {
            string MyMessage = message as string;
            var MessageBox = MessageBoxManager.GetMessageBoxStandard("提示", MyMessage, ButtonEnum.Ok, icon);
            if (MessageBox != null)
            {
                Window window = GetMainWindow();
                if (window != null)
                {
                    var Result = await MessageBox.ShowWindowDialogAsync(window);
                    return Result;
                }

            }
            return ButtonResult.None;
        }
        public static async Task<ButtonResult> ShowAsyncInMainWindow(string message, Icon icon,ButtonEnum buttonEnum)
        {
            string MyMessage = message as string;
            var MessageBox = MessageBoxManager.GetMessageBoxStandard("提示", MyMessage, buttonEnum, icon);
            if (MessageBox != null)
            {
                Window window = GetMainWindow();
                if (window != null)
                {
                    var Result = await MessageBox.ShowWindowDialogAsync(window);
                    return Result;
                }

            }
            return ButtonResult.None;
        }
    }
}
